package cn.edu.lingnan.servlet;

import cn.edu.lingnan.pojo.Competition;
import cn.edu.lingnan.service.ICompetitionService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.List;

@WebServlet("/queryAllCompete2")
public class queryCompete2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String comName = req.getParameter("comName");
        ICompetitionService service = new ICompetitionService();
        List<Competition> list = service.findCompetitionAll();
        List<Competition> list2 = service.findCompetitionByName(comName);
        HttpSession session = req.getSession();

        if (comName == null || comName.equals("")) {
            session.setAttribute("competitions", list);//默认查询所有比赛项目
        } else {
            session.setAttribute("competitions", list2);//模糊查询单个比赛项目
        }

        resp.sendRedirect(req.getContextPath() + "/user/CompeteRegister.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}